package com.zhb.cloud.plant.active.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhb.cloud.base.BaseController;
import com.zhb.cloud.core.JsonReturn;
import com.zhb.cloud.core.utils.PrizeUtils;
import com.zhb.cloud.plant.active.model.Prize;
import com.zhb.cloud.plant.active.service.PrizeService;
import com.zhb.cloud.utils.UUIDUtil;

@RestController
@RequestMapping("prize")
public class PrizeController extends BaseController {

	@Autowired
	private PrizeService prizeService;

	@PostMapping("init")
	public JsonReturn initPrize() {
		List<Prize> prizes = PrizeUtils.getPrizes();
		prizeService.batchInsert(prizes);
		return this.success(prizes);
	}

	@PostMapping("findAllPrize")
	public JsonReturn findAllPrize() {
		List<Prize> prizes = prizeService.findAllPrize();
		return this.success(prizes);
	}

	@PostMapping("insert")
	public JsonReturn insert() {
		JsonReturn jsonReturn = new JsonReturn();
		Prize prize1 = new Prize();
		prize1.setId(UUIDUtil.getId());
		prize1.setPrizeAmount(10);
		prize1.setPrizeName("iphonex");
		prize1.setPrizeWeight(new BigDecimal(0.01));
		prize1.setCreateTime(new Date());
		prize1.setUpdateTime(new Date());
		prizeService.saveModel(prize1);
		return jsonReturn;
	}
}
